package com.yzd.learnjava.arrays;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

import com.yzd.learnjava.util.Generated;
import com.yzd.learnjava.util.Print;

public class ComparatorTest {
	public static void main(String[] args) {
		CompType[] a = Generated.array(new CompType[12], CompType.generator());
		Print.print("before sorting : " + Arrays.toString(a));
		Arrays.sort(a, new ComptypeComparator());
		Print.print("after sorting : " + Arrays.toString(a));
	}
}

class ComptypeComparator implements Comparator<CompType>{

	public int compare(CompType o1, CompType o2) {
		return (o1.j < o2.j ? -1 : (o1.j == o2.j ? 0 : 1));
	}
	
}
